# $Id: Fichegen.pm,v 1.2 2004/06/21 12:12:30 ibo Exp $
package CGI::FOGE2::Fichegen;

use strict;
use CGI::FOGE2::Tools;

our @ISA = qw();

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    
    my %args = @_;
    my @mandatory_keys = ();
    my $self = {
	form => $args{form},
    };
    bless ($self, $class);
    return $self;
}

sub setform {
    my $self = shift;
    my ($form) = @_;
    $self->{form} = $form;
}

sub serve {
    my $self = shift;
    my $form = $self->{form};
    my $view = $form->{view};
    my $myself = CGI::script_name();

    my $out = ''; 

    my $db = $form->dbh_r();
    my $query = "SELECT id, t, ip\n";
    $query .=   "FROM $form->{dbAnswer}\n";
    $query .=   "WHERE enquiry = \'$form->{enquiry}\';\n";

    my $sth = $db->prepare($query);
    $sth->execute();

    $out .= CGI::start_table({-width => '100%'});
    $out .= CGI::th(['id', 'date', 'ip']);
    while (my $row = $sth->fetchrow_arrayref()) {
	my $vstr = '';
	if (defined $view) {$vstr = $view->as_query_string()};
	$row->[0] = CGI::a( {href => "$myself?action=fpf;id=$row->[0]$vstr",
			     -target =>'fiche'},
			    $row->[0]);
	$out .= CGI::Tr({-class=>'statrow'}, CGI::td($row));
    }
    $out .= CGI::end_table();
    $out .= CGI::h2($query);
    return $out;
}
1;
